package dao.impl;

import dao.BaseDao;
import dao.BaseDao02;
import dao.UserDao;
import org.apache.commons.dbutils.DbUtils;
import pojo.User;
import utils.JDBCUtils;

import java.sql.Connection;

public class UserDaoImpl extends BaseDao02 implements UserDao {
    @Override
    public User queryUserByUsername(String username) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ?";
        return queryForOne(sql,User.class,username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ? and password = ?;";
        return queryForOne(sql,User.class,username,password);
    }

    @Override
    public int saveUser(User user) {
        String sql = "INSERT INTO t_user(`username`,`password`,`email`) VALUES(?,?,?);";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }
}
